﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FormatUtil
{
    public static class BuildMsg
    {
        #region 获取即时拍照指令
        public static byte[] PhotoCommand(string DeviceID, int Ch, int CMD, int Interval, int SaveFlag, int Resolution,
            int Quality, int Brightness, int Contrast, int Saturation, int Chroma, int nMsgSerial = 0)
        {
            string MsgBody = GwUtil.IntToHex(Ch, 2);

            string strMsgSerial = GwUtil.IntToHex(GwUtil.IdGen808.GenId(), 4);

            if (nMsgSerial != 0)
            {
                strMsgSerial = GwUtil.IntToHex(nMsgSerial, 4);
            }

            MsgBody = MsgBody + GwUtil.IntToHex(CMD, 4) + GwUtil.IntToHex(Interval, 4) + GwUtil.IntToHex(SaveFlag, 2)
                + GwUtil.IntToHex(Resolution, 2) + GwUtil.IntToHex(Quality, 2) + GwUtil.IntToHex(Brightness, 2)
                + GwUtil.IntToHex(Contrast, 2) + GwUtil.IntToHex(Saturation, 2) + GwUtil.IntToHex(Chroma, 2);

            return GwUtil.BuildPackage(0x8801, DeviceID, MsgBody);
        }
        #endregion



        #region 人工确认报警
        public static byte[] PeopleHandle(string DeviceID, int SerNo, int AlarmType)
        {
            string MsgBody = GwUtil.IntToHex(SerNo, 4) + GwUtil.IntToHex(AlarmType, 8);
            return GwUtil.BuildPackage(0x8203, DeviceID, MsgBody);
        }
        #endregion

        #region 文本信息下发
        public static byte[] SendSMS(string DeviceID, int Flag, string Text, int msgSerial = 0)
        {
            string MsgBody = GwUtil.IntToHex(Flag, 2) + GwUtil.StrToHex(Text);
            return GwUtil.BuildPackage(0x8300, DeviceID, MsgBody, msgSerial);
        }
        #endregion

        #region 位置信息查询 点名
        public static byte[] RollCall(string DeviceID)
        {
            return GwUtil.BuildPackage(0x8201, DeviceID, "");
        }
        #endregion

        #region 临时位置跟踪控制 8202
        public static byte[] TemporaryTracking(string DeviceID, int Interval, int ExpiryDate)
        {
            string MsgBody = GwUtil.IntToHex(Interval, 4) + GwUtil.IntToHex(ExpiryDate, 8);
            return GwUtil.BuildPackage(0x8202, DeviceID, MsgBody);
        }
        #endregion

        #region 电话回拨
        public static byte[] PhoneCallBack(string DeviceID, int Flag, string PhoneNumber, int nMsgSerial808 = 0)
        {
            string MsgBody = GwUtil.IntToHex(Flag, 2) + GwUtil.StrToHex(PhoneNumber);
            return GwUtil.BuildPackage(0x8400, DeviceID, MsgBody, nMsgSerial808);
        }
        #endregion

        #region 设置电话本
        public static byte[] SetPhoneBook(string DeviceID, int SetType, int Count, List<string> Data)
        {
            string MsgBody = GwUtil.IntToHex(SetType, 2) + GwUtil.IntToHex(Count, 2);
            for (int i = 0; i < Count; i++)
            {
                string[] para = Data[i].Split('|');
                MsgBody = MsgBody + GwUtil.IntToHex(Convert.ToInt32(para[0]), 2) + GwUtil.IntToHex(para[1].Length, 2)
                    + GwUtil.StrToHex(para[1]) + GwUtil.IntToHex((GwUtil.StrToHex(para[2])).Length / 2, 2) + GwUtil.StrToHex(para[2]);
            }
            return GwUtil.BuildPackage(0x8401, DeviceID, MsgBody);
        }
        #endregion

        #region 车辆控制
        public static byte[] VehicleControl(string DeviceID, int ControlFlag)
        {
            string MsgBody = GwUtil.IntToHex(ControlFlag, 2);
            return GwUtil.BuildPackage(0x8500, DeviceID, MsgBody);
        }
        #endregion

        #region 终端控制
        public static byte[] TerminalControl(string DeviceID, string CMD, string Value, int serial808 = 0)
        {
            string MsgBody = string.Empty;
            switch (CMD)
            {
                case "1":
                    //无线升级
                    MsgBody = "01" + GwUtil.StrToHex(Value);
                    break;
                case "2":
                    //控制终端连接指定服务器
                    MsgBody = "02" + GwUtil.StrToHex(Value);
                    break;
                case "3":
                    //终端关机
                    MsgBody = GwUtil.IntToHex(3, 2);
                    break;
                case "4":
                    //终端复位
                    MsgBody = GwUtil.IntToHex(4, 2);
                    break;
                case "5":
                    //终端恢复出厂设置
                    MsgBody = GwUtil.IntToHex(5, 2);
                    break;
                case "6":
                    //关闭数据通信
                    MsgBody = GwUtil.IntToHex(6, 2);
                    break;
                case "7":
                    //关闭所有无线通信
                    MsgBody = GwUtil.IntToHex(7, 2);
                    break;
                case "64":
                    //断油电
                    MsgBody = "64";
                    //TODO:没有gps缓存 或 速度大于20km/h 不允许下发断油电
                    break;
                case "65":
                    //通油电
                    MsgBody = "65";
                    break;
                case "66":
                    //测试蜂鸣器--开
                    MsgBody = "66";
                    break;
                case "67":
                    //测试蜂鸣器--关
                    MsgBody = "67";
                    break;
                case "A0":
                    //设防 特殊用途
                    MsgBody = "A0";
                    break;
                case "A1":
                    //解防 特殊用途
                    MsgBody = "A1";
                    break;
            }

            return GwUtil.BuildPackage(0x8105, DeviceID, MsgBody, serial808);
        }
        #endregion

        #region 终端注销
        public static byte[] TerminalCancellation(string DeviceID)
        {
            return GwUtil.BuildPackage(0x0003, DeviceID, "");
        }
        #endregion

        #region 设置终端参数
        public static byte[] SetTerminalParameter(string DeviceID, int SetCount, List<string> Data)
        {
            string MsgBody = GwUtil.IntToHex(SetCount, 2);
            MsgBody += GwUtil.IntToHex(SetCount, 2); //分包参数个数
            string PValue = string.Empty;
            for (int i = 0; i < SetCount; i++)
            {
                string[] para = Data[i].Split('|');
                switch (para[0])
                {
                    #region 子命令
                    case "0001":
                        //设置终端心跳发送间隔，单位为(s)
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000001" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0002":
                        //TCP消息应答超时时间，单位为(s)
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000002" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0003":
                        //TCP消息重传次数
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000003" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0004":
                        //UDP消息应答超时时间，单位为秒(s)
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000004" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0005":
                        //UDP消息重传次数
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000005" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0006":
                        //SMS消息应答超时时间，单位为秒(s)
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000006" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0007":
                        //SMS消息重传次数
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000007" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0010":
                        //主服务器APN，无线通信拨号访问点。若网络制式为CDMA,则该处为PPP拨号号码
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000010" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0011":
                        //主服务器无线通信拨号用户名
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000011" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0012":
                        //主服务器无线通信拨号密码
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000012" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0013":
                        //主服务器地址，IP或域名
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000013" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0014":
                        //备份服务器APN,无线通信拨号访问点
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000014" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0015":
                        //备份服务器无线通信拨号用户名
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000015" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0016":
                        //备份服务器无线通信拨号密码
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000016" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0017":
                        //备份服务器地址，IP或域名
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000017" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0018":
                        //服务器TCP端口
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000018" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0019":
                        //服务器UDP端口
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000019" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0020":
                        //位置汇报策略，0：定时汇报；1：定距汇报；2：定时和定距汇报
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000020" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0021":
                        //位置汇报方案，0：根据ACC状态；1：根据登录状态和ACC状态，先判断登录状态，若登录再根据ACC状态
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000021" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0022":
                        //驾驶员未登录汇报时间间隔，单位为秒（s）, > 0
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000022" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0027":
                        //休眠时汇报时间间隔，单位为秒(s), > 0
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000027" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0028":
                        //紧急报警时汇报时间间隔单位为秒(s), > 0
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000028" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0029":
                        //缺省时间汇报间隔，单位为秒(s), > 0
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000029" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "002C":
                        //缺省距离汇报间隔，单位为米(m), > 0
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "0000002C" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "002D":
                        //驾驶员未登录汇报距离间隔，单位为米（m）, > 0
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "0000002D" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "002E":
                        //休眠时汇报距离间隔，单位为米(m), > 0
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "0000002E" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "002F":
                        //紧急报警时汇报距离间隔，单位为米（m）, > 0
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "0000002F" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0030":
                        //拐点补传角度， < 180
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000030" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0040":
                        //监控平台电话号码
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000040" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0041":
                        //复位电话号码，可采用此电话号码拨打终端电话让终端复位
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000041" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0042":
                        //恢复出厂设置电话号码，可采用此电话号码拨打终端电话让终端恢复出厂设置
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000042" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0043":
                        //监控平台SMS电话号码
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000043" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0044":
                        //接收终端SMS文本报警号码
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000044" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0045":
                        //终端接听电话策略，0：自动接听；1：ACC ON时自动接听，OFF时手动接听
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000045" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0046":
                        //每次最长通话时间，单位为秒（s），0为不允许通话，0xFFFFFFFF为不限制
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000046" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0047":
                        //当月最长通话时间，单位为秒（s），0为不允许通话，0xFFFFFFFF为不限制
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000047" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0048":
                        //监听电话号码
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000048" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0049":
                        //监管平台特权短信号码
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000049" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0050":
                        //报警屏蔽字，与位置信息汇报消息中的报警标志相对应，相应位为1则相应报警被屏蔽
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000050" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0051":
                        //报警发送文本SMS开关，与位置信息汇报消息中的报警标志相对应，相应为1则相应报警时发送文本SMS
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000051" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0052":
                        //报警拍摄开关，与位置信息汇报消息中的报警标志相对应，相应位为1则相应报警时摄像头拍摄，默认 第1路拍照
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000052" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0053":
                        //报警拍摄存储标志，与位置信息汇报消息中的报警标志相对应，相应位为1则对相应报警时拍的照片进行存储，否则实时上传
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000053" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0054":
                        //关键标志，与位置信息汇报消息中的报警标志相对应，相应位为1则对应报警为关键报警
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000054" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0055":
                        //最高速度，单位为千米每小时（km/h）
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000055" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0056":
                        //超速持续时间，单位为秒（s）
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000056" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0057":
                        //连续驾驶时间门限，单位为秒（s）
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000057" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0058":
                        //当天累计驾驶时间门限，单位为秒（s）
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000058" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0059":
                        //最小休息时间，单位为秒（s）
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000059" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "005A":
                        //最长停车时间，单位为秒（s）
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "0000005A" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0070":
                        //图像/视频质量，1~10， 1最好
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000070" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0071":
                        //亮度，0~255
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000071" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0072":
                        //对比度，0~127
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000072" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0073":
                        //饱和度，0~127
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000073" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0074":
                        //色度，0~255
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000074" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0080":
                        //车辆里程表读数，1/10km
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000080" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0081":
                        //车辆所在的省域ID
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 4);
                        MsgBody = MsgBody + "00000081" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0082":
                        //车辆所在的市域ID
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 4);
                        MsgBody = MsgBody + "00000082" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0083":
                        //公安交通管理部门颁发的机动车号牌
                        PValue = GwUtil.StrToHex(para[1]);
                        MsgBody = MsgBody + "00000083" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0084":
                        //车牌颜色，按照JT/T415--2006中5.4.12的规定
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        MsgBody = MsgBody + "00000084" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0085":
                        //车辆脉冲系数，车辆行驶1km距离过程中产生的脉冲信号个数
                        PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        MsgBody = MsgBody + "00000085" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                    case "0b00":
                        //是否开启指纹认证，0：关闭  1：开启
                        PValue = para[1].PadLeft(2,'0');
                        MsgBody = MsgBody + "00000b00" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        break;
                        ////扩展协议  以下是厂家自定义的协议 
                        //case "1001":
                        //    //透传口波特率设置
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        //    MsgBody = MsgBody + "00001001" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1002":
                        //    //摄像头口波特率设置
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        //    MsgBody = MsgBody + "00001002" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1003":
                        //    //打印机波特率设置
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        //    MsgBody = MsgBody + "00001003" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "100A":
                        //    //第A口波特率设置
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        //    MsgBody = MsgBody + "0000100A" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "100B":
                        //    //最小拍照时间间隔，单位：秒
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        //    MsgBody = MsgBody + "0000100B" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "100C":
                        //    //查询版本号
                        //    PValue = GwUtil.StrToHex(para[1]);
                        //    MsgBody = MsgBody + "0000100C" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "100D":
                        //    //防爆模式：0-普通，1-ACC防爆，2-区域防爆，3-ACC + 区域；
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "0000100D" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "100E":
                        //    //报警提示方式：0-内置蜂鸣器，1-外置蜂鸣器，2-TTS，3-内置蜂鸣器 + TTS
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "0000100E" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "100F":
                        //    //预超速提前量，单位：公里/小时
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "0000100F" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1010":
                        //    //预疲劳提前量，单位：分钟
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "00001010" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1011":
                        //    //设置预超速提示语音内容，长度不超过100个字节，TTS协议格式
                        //    PValue = GwUtil.StrToHex(para[1]);
                        //    MsgBody = MsgBody + "00001011" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1012":
                        //    //设置超速提示语音内容，长度不超过100个字节，TTS协议格式
                        //    PValue = GwUtil.StrToHex(para[1]);
                        //    MsgBody = MsgBody + "00001012" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1013":
                        //    //设置预疲劳语音提示内容，长度不超过100个字节，TTS协议格式
                        //    PValue = GwUtil.StrToHex(para[1]);
                        //    MsgBody = MsgBody + "00001013" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1014":
                        //    //设置疲劳语音提示内容，长度不超过100个字节，TTS协议格式
                        //    PValue = GwUtil.StrToHex(para[1]);
                        //    MsgBody = MsgBody + "00001014" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1015":
                        //    //区间拍照，（开始时间(BCD[2]) + 结束时间(BCD[2]) + 间隔时间(BYTE)） * 8
                        //    //支持8个时间区间，固定长度为5 * 8 = 40个字节
                        //    //默认 第1路拍照，间隔时间单位为分钟
                        //    //PValue = StrToHex(para[1]);
                        //    PValue = para[1];
                        //    MsgBody = MsgBody + "00001015" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1016":
                        //    //CAN/485设置，0 - 普通，1-can，2-485
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "00001016" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1017":
                        //    //是否启用转鼓检测，0-不启用，1-启用
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "00001017" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1018":
                        //    //ACC是否与位置刷新关联  0-不关联，1-关联；
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "00001018" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1019":
                        //    //ACC是否与电子速度关联 0-不关联，1-关联
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "00001019" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1020":
                        //    //录像设备传送信息开关
                        //    //0x00-关(不向录像设备发送信息，并失效所有关于与录像设备交互的指令与处理逻辑)
                        //    //0x01-开(需要向录像设备发送信息) 终端出厂，默认值是0x00
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "00001020" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1021":
                        //    //定时提取录像设备状态间隔时间，单位：秒，取值范围(15-255)
                        //    //终端出厂，默认值是0x0F，
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "00001021" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1022":
                        //    //设置SD卡图片存储间隔时间
                        //    //摄像头号 + 分辨率 + 存储间隔时间
                        //    //摄像头号：1字节<低4位分表表示指定摄像头，例B3B2B1B0分别表示1路2路3路4路>
                        //    //分辨率：1字节<1:320 * 240,2:640 * 480>
                        //    //存储间隔时间：2字节，单位秒，为0则停止
                        //    PValue = para[1];
                        //    MsgBody = MsgBody + "00001022" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1023":
                        //    //设置ACC与拍照关联，(如果设置ACC关联了，则当ACC关时定时区间拍照和SD卡定时存储失效，直到ACC打开)
                        //    //0-不关联， 1-关联
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "00001023" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1024":
                        //    //设置自定义状态触发拍照开关，与位置信息汇报消息中的状态相对应，相应位为1则对相应状态位触发进行摄像头拍摄
                        //    //注：目前 只支持门磁、自定义高1、自定义高2、自定义低1、自定义低2 默认 第1路拍照
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        //    MsgBody = MsgBody + "00001024" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1025":
                        //    //设置自定义状态触发拍照存储标志，与位置信息汇报消息中的状态相对应，相应位为1则对相应状态位触发时拍的照片进行存储，否则实时上传
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 8);
                        //    MsgBody = MsgBody + "00001025" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1026":
                        //    //设置报警拍照属性1字节 对应0x0052协议
                        //    //<低4位分别表示指定摄像头，例B3B2B1B0分别表示1路2路3路4路>
                        //    //<高4位表示分辨率：1:320 * 240， 2:640 * 480>
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "00001026" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1027":
                        //    //设置报警区间拍照属性 对应0x1015协议
                        //    //<低4位分别表示指定摄像头，例B3B2B1B0分别表示1路2路3路4路>
                        //    //<高4位表示分辨率：1:320 * 240， 2:640 * 480>
                        //    //para[1]= "1F"
                        //    //PValue = IntToHex(Convert.ToInt32(para[1]), 2);
                        //    PValue = para[1];
                        //    MsgBody = MsgBody + "00001027" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;
                        //case "1028":
                        //    //设置自定义状态触发拍照属性 对应0x1024协议
                        //    //<低4位分别表示指定摄像头，例B3B2B1B0分别表示1路2路3路4路>
                        //    //<高4位表示分辨率：1:320 * 240， 2:640 * 480>
                        //    PValue = GwUtil.IntToHex(Convert.ToInt32(para[1]), 2);
                        //    MsgBody = MsgBody + "00001028" + GwUtil.IntToHex(PValue.Length / 2, 2) + PValue;
                        //    break;


                        #endregion
                }
            }
            return GwUtil.BuildPackage(0x8103, DeviceID, MsgBody);
        }
        #endregion

        #region 查询终端参数
        public static byte[] QueryTerminalParameter(string DeviceID)
        {
            return GwUtil.BuildPackage(0x8104, DeviceID, "");
        }
        #endregion

        #region 查询指定终端参数
        public static byte[] QuerySpecifyTerminalParameter(string DeviceID, int SetCount, List<string> Data)
        {
            string MsgBody = GwUtil.IntToHex(SetCount, 2);
            for (int i = 0; i < SetCount; i++)
            {
                MsgBody += Data[i];
            }
            return GwUtil.BuildPackage(0x8106, DeviceID, MsgBody);
        }
        #endregion

        #region 信息点播菜单设置
        public static byte[] SetInfoMenu(string DeviceID, int SetType, int SetCount, List<string> Data)
        {
            string MsgBody = GwUtil.IntToHex(SetType, 2) + GwUtil.IntToHex(SetCount, 2);
            for (int i = 0; i < SetCount; i++)
            {
                string[] para = Data[i].Split('|');
                byte[] bts = Encoding.Default.GetBytes(para[1]);

                MsgBody = MsgBody + GwUtil.IntToHex(Convert.ToInt32(para[0]), 2) + GwUtil.IntToHex(bts.Length, 4)
                    + GwUtil.StrToHex(para[1]);
            }
            return GwUtil.BuildPackage(0x8303, DeviceID, MsgBody);
        }
        #endregion

        #region 设置圆形区域
        public static byte[] CircularAreaSet(string DeviceID, int SetType, int Count, List<string> Data)
        {
            string MsgBody = GwUtil.IntToHex(SetType, 2) + GwUtil.IntToHex(Count, 2);//设置属性 + 区域总数
            if (Count > 0)
            {
                for (int i = 0; i < Count; i++)
                {
                    string[] para = Data[i].Split('|');
                    string strZoneAttr = GwUtil.IntToBin(Convert.ToInt32(para[1]), 16);

                    MsgBody += GwUtil.IntToHex(Convert.ToInt32(para[0]), 8) + GwUtil.IntToHex(Convert.ToInt32(para[1]), 4);//区域id + 区域属性
                    MsgBody += GwUtil.IntToHex((int)(Convert.ToDouble(para[2]) * 1000000), 8);//纬度
                    MsgBody += GwUtil.IntToHex((int)(Convert.ToDouble(para[3]) * 1000000), 8);//经度
                    MsgBody += GwUtil.IntToHex(Convert.ToInt32(para[4]), 8); //半径

                    if (strZoneAttr[15 - 0] == '1') //区域属性0位为1，则有该字段
                    {
                        MsgBody += para[5];//起始时间
                        MsgBody += para[6];//结束时间
                    }

                    if (strZoneAttr[15 - 1] == '1') //区域属性1位为1，则有该字段
                    {
                        MsgBody += GwUtil.IntToHex(Convert.ToInt32(para[7]), 4);//最高速度
                        MsgBody += GwUtil.IntToHex(Convert.ToInt32(para[8]), 2);//超速持续时间
                    }
                }
            }
            return GwUtil.BuildPackage(0x8600, DeviceID, MsgBody);
        }
        #endregion

        #region 删除圆形区域
        public static byte[] CircularAreaDel(string DeviceID, int Count, List<string> Data)
        {
            string MsgBody = GwUtil.IntToHex(Count, 2);
            if (Count > 0)
            {
                for (int i = 0; i < Count; i++)
                {
                    MsgBody = MsgBody + GwUtil.IntToHex(Convert.ToInt32(Data[i]), 8);
                }
            }
            return GwUtil.BuildPackage(0x8601, DeviceID, MsgBody);
        }
        #endregion

        #region 设置矩形区域
        public static byte[] RectangularAreaSet(string DeviceID, int SetType, int Count, List<string> Data)
        {
            string MsgBody = GwUtil.IntToHex(SetType, 2) + GwUtil.IntToHex(Count, 2);
            for (int i = 0; i < Count; i++)
            {
                string[] para = Data[i].Split('|');
                string strZoneAttr = GwUtil.IntToBin(Convert.ToInt32(para[1]), 16);

                MsgBody += GwUtil.IntToHex(Convert.ToInt32(para[0]), 8);
                MsgBody += GwUtil.IntToHex(Convert.ToInt32(para[1]), 4);
                MsgBody += GwUtil.IntToHex((int)(Convert.ToDouble(para[2]) * 1000000), 8);
                MsgBody += GwUtil.IntToHex((int)(Convert.ToDouble(para[3]) * 1000000), 8);
                MsgBody += GwUtil.IntToHex((int)(Convert.ToDouble(para[4]) * 1000000), 8);
                MsgBody += GwUtil.IntToHex((int)(Convert.ToDouble(para[5]) * 1000000), 8);

                if (strZoneAttr[15 - 0] == '1')
                {
                    MsgBody += para[6];
                    MsgBody += para[7];
                }

                if (strZoneAttr[15 - 1] == '1')
                {
                    MsgBody += GwUtil.IntToHex(Convert.ToInt32(para[8]), 4);
                    MsgBody += GwUtil.IntToHex(Convert.ToInt32(para[9]), 2);
                }
            }
            return GwUtil.BuildPackage(0x8602, DeviceID, MsgBody);
        }
        #endregion

        #region 删除矩形区域
        public static byte[] RectangularAreaDel(string DeviceID, int Count, List<string> Data)
        {
            string MsgBody = GwUtil.IntToHex(Count, 2);
            if (Count > 0)
            {
                for (int i = 0; i < Count; i++)
                {
                    MsgBody = MsgBody + GwUtil.IntToHex(Convert.ToInt32(Data[i]), 8);
                }
            }
            return GwUtil.BuildPackage(0x8603, DeviceID, MsgBody);
        }
        #endregion

        #region 设置多边形区域
        public static byte[] PolygonAreaSet(string DeviceID, int AreaID, int AreaProp, string BeginTime,
            string EndTime, int MaxSpeed, int LastTime, int PointCount, string Points)
        {
            string MsgBody = string.Empty;
            string strZoneAttr = GwUtil.IntToBin(AreaProp, 16);

            MsgBody += GwUtil.IntToHex(AreaID, 8) + GwUtil.IntToHex(AreaProp, 4); //区域id + 区域属性

            if (strZoneAttr[15 - 0] == '1')
            {
                MsgBody += BeginTime + EndTime;
            }

            if (strZoneAttr[15 - 1] == '1')
            {
                MsgBody += GwUtil.IntToHex(MaxSpeed, 4) + GwUtil.IntToHex(LastTime, 2);
            }

            MsgBody = MsgBody + GwUtil.IntToHex(PointCount, 4);
            string[] para = Points.Split('|');
            for (int i = 0; i < para.Length / 2; i++)
            {
                MsgBody = MsgBody + GwUtil.IntToHex((int)(Convert.ToDouble(para[2 * i]) * 1000000), 8)
                    + GwUtil.IntToHex((int)(Convert.ToDouble(para[2 * i + 1]) * 1000000), 8);
            }
            return GwUtil.BuildPackage(0x8604, DeviceID, MsgBody);
        }
        #endregion

        #region 删除多边形区域
        public static byte[] PolygonAreaDel(string DeviceID, int AreaCount, List<string> Data)
        {
            string MsgBody = GwUtil.IntToHex(AreaCount, 2);
            for (int i = 0; i < Data.Count; i++)
            {
                MsgBody = MsgBody + Data[i];
            }
            return GwUtil.BuildPackage(0x8605, DeviceID, MsgBody);
        }
        #endregion

        #region 设置路线 
        public static byte[] LineSet(string DeviceID, int LineID, int LineProp, string BeginTime, string EndTime, int PointCount, List<string> Data)
        {
            string strLineAttr = GwUtil.IntToBin(LineProp, 16);

            string MsgBody = GwUtil.IntToHex(LineID, 8) + GwUtil.IntToHex(LineProp, 4);

            if (strLineAttr[15 - 0] == '1')
            {
                MsgBody += BeginTime + EndTime;
            }

            MsgBody += GwUtil.IntToHex(PointCount, 4);
            for (int i = 0; i < PointCount; i++)
            {
                string[] para = Data[i].Split('|');
                string strItemAttr = GwUtil.IntToBin(Convert.ToInt32(para[5]), 8);//路段属性

                MsgBody = MsgBody + GwUtil.IntToHex(Convert.ToInt32(para[0]), 8) + GwUtil.IntToHex(Convert.ToInt32(para[1]), 8)
                    + GwUtil.IntToHex((int)(Convert.ToDouble(para[2]) * 1000000), 8) + GwUtil.IntToHex((int)(Convert.ToDouble(para[3]) * 1000000), 8)
                    + GwUtil.IntToHex(Convert.ToInt32(para[4]), 2) + GwUtil.IntToHex(Convert.ToInt32(para[5]), 2);

                if (strItemAttr[7 - 0] == '1')
                {
                    MsgBody += GwUtil.IntToHex(Convert.ToInt32(para[6]), 4) + GwUtil.IntToHex(Convert.ToInt32(para[7]), 4);//路段行驶过长阈值 路段行驶不足阈值
                }

                if (strItemAttr[7 - 1] == '1')
                {
                    MsgBody += GwUtil.IntToHex(Convert.ToInt32(para[8]), 4) + GwUtil.IntToHex(Convert.ToInt32(para[9]), 2);//路段最高速度 路段超速持续时间
                }
            }
            return GwUtil.BuildPackage(0x8606, DeviceID, MsgBody);
        }
        #endregion

        #region 删除路线
        public static byte[] LineDel(string DeviceID, int LineCount, List<string> Data)
        {
            string sd = string.Empty;
            string MsgBody = GwUtil.IntToHex(LineCount, 2);
            for (int i = 0; i < Data.Count; i++)
            {
                MsgBody = MsgBody + Data[i];
            }
            return GwUtil.BuildPackage(0x8607, DeviceID, MsgBody);
        }
        #endregion

        #region 事件设置
        public static byte[] EventSet(string DeviceID, int SetType, int Count, List<string> Data)
        {
            string MsgBody = string.Empty;
            if (SetType == 0)
                MsgBody = GwUtil.IntToHex(SetType, 2);
            else
                MsgBody = GwUtil.IntToHex(SetType, 2) + GwUtil.IntToHex(Count, 2);
            if (SetType == 4)
            {
                for (int i = 0; i < Count; i++)
                {
                    MsgBody = MsgBody + GwUtil.IntToHex(Convert.ToInt32(Data[i]), 2) + "00";
                }
            }
            else
            {
                for (int i = 0; i < Count; i++)
                {
                    string[] para = Data[i].Split('|');
                    MsgBody = MsgBody + GwUtil.IntToHex(Convert.ToInt32(para[0]), 2)
                        + GwUtil.IntToHex((GwUtil.StrToHex(para[1])).Length / 2, 2)
                        + GwUtil.StrToHex(para[1]);
                }
            }
            return GwUtil.BuildPackage(0x8301, DeviceID, MsgBody);
        }
        #endregion

        #region 存储多媒体数据检索
        public static byte[] SearchMultiMedia(string DeviceID, int MultiMediaType, int Ch, int EventType, string BeginTime, string EndTime, int serial)
        {
            string MsgBody = GwUtil.IntToHex(MultiMediaType, 2) + GwUtil.IntToHex(Ch, 2) + GwUtil.IntToHex(EventType, 2) + BeginTime + EndTime;
            return GwUtil.BuildPackage(0x8802, DeviceID, MsgBody, serial);
        }
        #endregion

        #region 存储多媒体数据上传
        public static byte[] SearchMultiMediaUpload(string DeviceID, int MultiMediaType, int Ch, int EventType, string BeginTime, string EndTime, int DelFlag)
        {
            string MsgBody = GwUtil.IntToHex(MultiMediaType, 2) + GwUtil.IntToHex(Ch, 2) + GwUtil.IntToHex(EventType, 2) + BeginTime + EndTime + GwUtil.IntToHex(DelFlag, 2);
            return GwUtil.BuildPackage(0x8803, DeviceID, MsgBody);
        }
        #endregion

        #region 单条存储多媒体数据检索上传命令
        public static byte[] SearchSingleMulMediaUpload(string DeviceID, int MultiMediaId, int DelFlag)
        {
            string MsgBody = GwUtil.IntToHex(MultiMediaId, 8) + GwUtil.IntToHex(DelFlag, 2);
            return GwUtil.BuildPackage(0x8805, DeviceID, MsgBody);
        }
        #endregion

        #region 提问下发
        public static byte[] QuestionsSend(string DeviceID, int Lsh, int Flag, string Question, int AnswerCount, List<string> Data)
        {
            string sd = string.Empty;
            string MsgBody = GwUtil.IntToHex(Flag, 2) + GwUtil.IntToHex((GwUtil.StrToHex(Question)).Length / 2, 2) + GwUtil.StrToHex(Question);
            for (int i = 0; i < AnswerCount; i++)
            {
                string[] para = Data[i].Split('|');
                MsgBody = MsgBody + GwUtil.IntToHex(Convert.ToInt32(para[0]), 2) +
                    GwUtil.IntToHex((GwUtil.StrToHex(para[1])).Length / 2, 4) + GwUtil.StrToHex(para[1]);
            }
            return GwUtil.BuildPackage(0x8302, DeviceID, MsgBody);
        }
        #endregion

        #region 信息服务
        public static byte[] InformationService(string DeviceID, int Flag, string Info)
        {
            string MsgBody = GwUtil.IntToHex(Flag, 2) + GwUtil.IntToHex((GwUtil.StrToHex(Info)).Length / 2, 4) + GwUtil.StrToHex(Info);
            return GwUtil.BuildPackage(0x8304, DeviceID, MsgBody);
        }
        #endregion

        #region 录音开始命令
        public static byte[] SoundRecording(string DeviceID, int Command, int Time, int SaveFlag, int Rate)
        {
            string MsgBody = GwUtil.IntToHex(Command, 2) + GwUtil.IntToHex(Time, 4) + GwUtil.IntToHex(SaveFlag, 2) + GwUtil.IntToHex(Rate, 2);
            return GwUtil.BuildPackage(0x8804, DeviceID, MsgBody);
        }
        #endregion

        #region 采集行驶记录仪数据
        public static byte[] RunningRecordingDataGet(string DeviceID, int Command, int nSerial808 = 0)
        {
            string MsgBody = GwUtil.IntToHex(Command, 2);
            return GwUtil.BuildPackage(0x8700, DeviceID, MsgBody, nSerial808);
        }
        #endregion

        #region 设置行驶记录仪参数
        public static byte[] RunningRecordingDataSet(string DeviceID, string Command, string Data)
        {
            string sd = string.Empty;
            //string CMD = IntToHex(Command, 2);
            string CMD = Command;
            string[] para = Data.Split('|');
            string MsgBody = CMD;
            switch (CMD)
            {
                case "81":
                    //设置驾驶员代码、驾驶证号码
                    MsgBody = MsgBody + GwUtil.IntToHex(Convert.ToInt32(para[0]), 6) + GwUtil.StrToHex(para[1], 36);
                    break;
                case "82":
                    //设置记录仪中的车辆VIP号、车牌号码、分类
                    MsgBody = MsgBody + GwUtil.StrToHex(para[0], 34) + GwUtil.StrToHex(para[1], 24) + GwUtil.StrToHex(para[2], 24);
                    break;
                case "C2":
                    //设置记录仪时钟
                    MsgBody = MsgBody + para[0] + para[1] + para[2] + para[3] + para[4] + para[5];
                    break;
                case "C3":
                    //设置车辆特征系数
                    MsgBody = MsgBody + Gen8701C3(para[0])/*IntToHex(Convert.ToInt32(para[0]), 6)*/;
                    break;
            }
            return GwUtil.BuildPackage(0x8701, DeviceID, MsgBody);
        }

        private static string Gen8701C3(string para)
        {
            string body = "AA75C3000800" + DateTime.Now.ToString("yyMMddHHmmss");
            body += GwUtil.IntToHex(Convert.ToInt32(para), 4);
            body += GwUtil.GetCheckCode(body);
            return body;
        }

        #endregion

        #region 数据下行透传
        public static byte[] TransparentDataDownLoad(string DeviceID, int msgtype, string data)
        {
            string MsgBody = GwUtil.IntToHex(msgtype, 2) + (data);
            return GwUtil.BuildPackage(0x8900, DeviceID, MsgBody);
        }
        #endregion

        #region 补传分包请求
        public static byte[] RequestOtherPackage(string DeviceID, int num, int packageNum, List<int> packageList)
        {
            string MsgBody = GwUtil.IntToHex(num, 4) + GwUtil.IntToHex(packageNum, 2);
            for (int i = 0; i < packageNum; i++)
            {
                MsgBody = MsgBody + GwUtil.IntToHex(packageList[i], 4);
            }
            return GwUtil.BuildPackage(0x8003, DeviceID, MsgBody);
        }
        #endregion

        /// <summary>
        /// 平台登录请求 0x01F0
        /// </summary>
        /// <returns></returns>
        static public byte[] platformLogin(string DeviceID, string plat, string pwd, int accessCode)
        {
            DeviceID = DeviceID.PadLeft(16, '0').Substring(0, 16);
            StringBuilder sb = new StringBuilder();
            sb.Append(GwUtil.StrToHex(plat));
            sb.Append(GwUtil.StrToHex(pwd));
            sb.Append(GwUtil.IntToHex(accessCode, 8));
            return GwUtil.BuildPackage(0x01F0, DeviceID, sb.ToString());
        }

        /// <summary>
        /// 平台登出请求消息 0x01F1
        /// </summary>
        /// <param name="plat"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        static public byte[] platformLogout(string DeviceID, string plat, string pwd)
        {
            DeviceID = DeviceID.PadLeft(16, '0').Substring(0, 16);
            StringBuilder sb = new StringBuilder();
            sb.Append(GwUtil.StrToHex(plat));
            sb.Append(GwUtil.StrToHex(pwd));
            return GwUtil.BuildPackage(0x01F1, DeviceID, sb.ToString());
        }

        #region 扩展计时培训消息内容定义
        /// <summary>
        /// 添加扩展消息头
        /// </summary>
        /// <param name="msgID"></param>
        /// <param name="packNum"></param>
        /// <param name="terNum"></param>
        /// <param name="dataLen"></param>
        /// <param name="data"></param>
        /// <param name="msgType"></param>
        /// <param name="response"></param>
        /// <param name="encry"></param>
        /// <returns></returns>
        static public byte[] addExtendMsg(byte[] msgID, int packNum, string terNum, int dataLen, byte[] data, byte msgType = 0, byte response = 0, byte encry = 0)
        {
            byte[] sendByte = new byte[26 + dataLen];
            Buffer.BlockCopy(msgID, 0, sendByte, 0, 2);
            byte msgPara = 0;
            if (1 == msgType)
            {
                msgPara += 1;
            }
            if (1 == response)
            {
                msgPara += 2;
            }
            if (1 == encry)
            {
                msgPara += 16;
            }
            else if (2 == encry)
            {
                msgPara += 32;
            }
            byte[] msgParaArr = { 0, msgPara };
            Buffer.BlockCopy(msgParaArr, 0, sendByte, 2, 2);
            sendByte[4] = (byte)(packNum / 256);
            sendByte[5] = (byte)(packNum % 256);
            byte[] terNumArr = GwUtil.HexToBytes(GwUtil.StrToHex(terNum.PadLeft(16, '0').Substring(0, 16)));
            Buffer.BlockCopy(terNumArr, 0, sendByte, 6, 16);
            Buffer.BlockCopy(GwUtil.HexToBytes(GwUtil.IntToHex(dataLen, 8)),0,sendByte,22,4);

            if (0 != dataLen)
            {
                Buffer.BlockCopy(data, 0, sendByte, 26, dataLen);
            }
            //平台发送的扩展消息无此字段,校验串

            return sendByte;
        }

        /// <summary>
        ///教练员登录应答
        /// </summary>
        /// <param name="result"></param>
        /// <param name="trainerNum"></param>
        /// <param name="readAddMsg"></param>
        /// <param name="len"></param>
        /// <param name="addMsg"></param>
        /// <returns></returns>
        static public byte[] trainerLoginResponse(byte result, string trainerNumStr, byte readAddMsg, byte len, string addMsg)
        {
            byte[] sendByte = new byte[19 + len];
            sendByte[0] = result;
            byte[] trainerNum = GwUtil.HexToBytes(GwUtil.StrToHex(trainerNumStr));
            Buffer.BlockCopy(trainerNum, 0, sendByte, 1, 16);
            sendByte[17] = readAddMsg;
            sendByte[18] = len;
            if (0 != len)
            {
                byte[] strbytes = Encoding.GetEncoding("GBK").GetBytes(addMsg);
                Buffer.BlockCopy(strbytes, 0, sendByte, 19, len);
            }
            return sendByte;
        }

        /// <summary>
        /// 教练员登出应答
        /// </summary>
        /// <param name="result"></param>
        /// <param name="trainerNum"></param>
        /// <returns></returns>
        static public byte[] trainerLogonResponse(byte result, string trainerNumStr)
        {
            byte[] sendByte = new byte[17];
            sendByte[0] = result;
            byte[] trainerNum = GwUtil.HexToBytes(GwUtil.StrToHex(trainerNumStr));
            Buffer.BlockCopy(trainerNum, 0, sendByte, 1, 16);
            return sendByte;
        }

        /// <summary>
        ///学员登录应答
        /// </summary>
        /// <param name="result"></param>
        /// <param name="traineeNum"></param>
        /// <param name="totalTime"></param>
        /// <param name="nowTime"></param>
        /// <param name="totalMileage"></param>
        /// <param name="nowMileage"></param>
        /// <param name="readAddMsg"></param>
        /// <param name="len"></param>
        /// <param name="addMsg"></param>
        /// <returns></returns>
        static public byte[] traineeLoginResponse(byte result, byte[] traineeNum, byte[] totalTime, byte[] nowTime, byte[] totalMileage, byte[] nowMileage, byte readAddMsg, byte len, string addMsg)
        {
            byte[] sendByte = new byte[27 + len];
            sendByte[0] = result;
            Buffer.BlockCopy(traineeNum, 0, sendByte, 1, 16);
            Buffer.BlockCopy(totalTime, 0, sendByte, 17, 2);
            Buffer.BlockCopy(nowTime, 0, sendByte, 19, 2);
            Buffer.BlockCopy(totalMileage, 0, sendByte, 21, 2);
            Buffer.BlockCopy(nowMileage, 0, sendByte, 23, 2);
            sendByte[25] = readAddMsg;
            sendByte[26] = len;
            if (0 != len)
            {
                byte[] strbytes = Encoding.GetEncoding("GBK").GetBytes(addMsg);
                Buffer.BlockCopy(strbytes, 0, sendByte, 27, len);
            }

            return sendByte;
        }

        /// <summary>
        ///学员登出应答
        /// </summary>
        /// <param name="result"></param>
        /// <param name="traineeNum"></param>
        /// <returns></returns>
        static public byte[] traineeLogonResponse(byte result, byte[] traineeNum)
        {
            byte[] sendByte = new byte[17];
            sendByte[0] = result;
            Buffer.BlockCopy(traineeNum, 0, sendByte, 1, 16);
            return sendByte;
        }

        /// <summary>
        /// 命令上报学时记录
        /// </summary>
        /// <param name="queryWay"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="queryNum"></param>
        /// <returns></returns>
        static public byte[] commandReportingPeriod(byte queryWay, byte[] startTime, byte[] endTime, int queryNum)
        {
            byte[] sendByte = new byte[15];
            sendByte[0] = queryWay;
            Buffer.BlockCopy(startTime, 0, sendByte, 1, 6);
            Buffer.BlockCopy(endTime, 0, sendByte, 7, 6);
            sendByte[13] = (byte)(queryNum / 256);
            sendByte[14] = (byte)(queryNum % 256);

            return sendByte;
        }

        /// <summary>
        ///　立即拍照
        /// </summary>
        /// <param name="uploadMode">上传模式</param>
        /// <param name="passNum">摄像头通道号</param>
        /// <param name="photoSize">图片尺寸</param>
        /// <returns></returns>
        static public byte[] immediatelyPhoto(byte uploadMode, byte passNum, byte photoSize)
        {
            byte[] sendByte = new byte[3];
            sendByte[0] = uploadMode;
            sendByte[1] = passNum;
            sendByte[2] = photoSize;
            return sendByte;
        }

        /// <summary>
        /// 查询照片 8302
        /// </summary>
        /// <param name="queryMode">查询方式</param>
        /// <param name="startTime">查询开始时间</param>
        /// <param name="endTime">查询结束时间</param>
        /// <returns></returns>
        static public byte[] queryPhoto(byte queryMode, byte[] startTime, byte[] endTime)
        {
            byte[] sendByte = new byte[13];
            sendByte[0] = queryMode;
            Buffer.BlockCopy(startTime, 0, sendByte, 1, 6);
            Buffer.BlockCopy(endTime, 0, sendByte, 7, 6);
            return sendByte;
        }

        /// <summary>
        /// 上报照片查询结果应答 8303
        /// </summary> 
        /// <param name="responseCode">应答代码</param>
        /// <param name="packNum">原始驾陪包序号</param>
        /// <returns></returns>
        static public byte[] queryPhotoResponse(byte responseCode, int packNum)
        {
            byte[] sendByte = new byte[15];
            sendByte[0] = responseCode;
            sendByte[1] = (byte)(packNum / 256);
            sendByte[2] = (byte)(packNum % 256);

            return sendByte;
        }

        /// <summary>
        /// 上传指定照片 8304
        /// </summary>
        /// <param name="photoNum">照片编号</param>
        /// <returns></returns>
        static public byte[] uploadThisPhoto(byte[] photoNum)
        {
            byte[] sendByte = new byte[10];
            Buffer.BlockCopy(photoNum, 0, sendByte, 0, 10);
            return sendByte;
        }

        /// <summary>
        /// 照片上传初始化应答
        /// </summary>
        /// <param name="responseCode">应答代码</param>
        /// <returns></returns>
        static public byte[] photoUploadResponse(byte responseCode)
        {
            byte[] sendByte = new byte[1];
            sendByte[0] = responseCode;
            return sendByte;
        }

        /// <summary>
        /// 设置计时终端应用参数
        /// </summary>
        /// <param name="paraNum"></param>
        /// <param name="timeInterval"></param>
        /// <param name="uploadSet"></param>
        /// <param name="readAddMsg"></param>
        /// <param name="stopTime"></param>
        /// <param name="gnssDataTime"></param>
        /// <param name="autoLogonTime"></param>
        /// <param name="reAuthTime"></param>
        /// <param name="teach"></param>
        /// <param name="learn"></param>
        /// <returns></returns>
        static public byte[] setTerminalPara(byte paraNum, byte timeInterval, byte uploadSet, byte readAddMsg, byte stopTime, byte[] gnssDataTime, byte[] autoLogonTime, byte[] reAuthTime, byte teach, byte learn,int ReTime)
        {
            byte[] sendByte = new byte[15];
            sendByte[0] = paraNum;
            sendByte[1] = timeInterval;
            sendByte[2] = uploadSet;
            sendByte[3] = readAddMsg;
            sendByte[4] = stopTime;
            if (gnssDataTime.Length == 1)
            {
                sendByte[5] = 0x00;
                sendByte[6] = gnssDataTime[0];
            }
            else
            {
                Buffer.BlockCopy(gnssDataTime, 0, sendByte, 5, 2);
            }

            if (autoLogonTime.Length == 1)
            {
                sendByte[7] = 0x00;
                sendByte[8] = autoLogonTime[0];
            }
            else
            {
                Buffer.BlockCopy(autoLogonTime, 0, sendByte, 7, 2);
            }

            if (reAuthTime.Length == 1)
            {
                sendByte[8] = 0x00;
                sendByte[10] = reAuthTime[0];
            }
            else
            {
                Buffer.BlockCopy(reAuthTime, 0, sendByte, 9, 2);
            }

            sendByte[11] = teach;
            sendByte[12] = learn;
            sendByte[13] = (byte)(ReTime / 256);
            sendByte[14] = (byte)(ReTime % 256);
            return sendByte;
        }

        /// <summary>
        /// 设置禁训状态
        /// </summary>
        /// <param name="state"></param>
        /// <param name="len"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        static public byte[] setNoTrainState(byte state, byte len, string content)
        {
            byte[] sendByte = new byte[2 + len];
            sendByte[0] = state;
            sendByte[1] = len;
            if (0 != len)
            {
                byte[] strbytes = Encoding.GetEncoding("GBK").GetBytes(content);
                Buffer.BlockCopy(strbytes, 0, sendByte, 2, len);
            }

            return sendByte;
        }

        //查询计时终端应用参数 0x8503 消息体为空

        /// <summary>
        /// 请求身份认证信息应答
        /// </summary>
        /// <param name="packNum"></param>
        /// <param name="result"></param>
        /// <param name="len"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        static public byte[] requestIDInfoResponse(int packNum, byte result, int len, byte[] content)
        {
            if (result==0)
            {
                byte[] sendByte = new byte[7 + len];
                sendByte[0] = (byte)(packNum / 256);
                sendByte[1] = (byte)(packNum % 256);
                sendByte[2] = result;

                byte[] lenArr = System.BitConverter.GetBytes(len);
                Array.Reverse(lenArr);
                Buffer.BlockCopy(lenArr, 0, sendByte, 3, 4);
                Buffer.BlockCopy(content, 0, sendByte, 7, len);

                return sendByte;
            }
            else
            {
                byte[] sendByte = new byte[3];
                sendByte[0] = (byte)(packNum / 256);
                sendByte[1] = (byte)(packNum % 256);
                sendByte[2] = result;
                return sendByte;
            }
        }

        /// <summary>
        /// 请求统一编号信息应答
        /// </summary>
        /// <param name="packNum"></param>
        /// <param name="result"></param>
        /// <param name="uniformNum"></param>
        /// <returns></returns>
        static public byte[] requestUniformNumResponse(int packNum, byte result, byte[] uniformNum, byte[] carType)
        {
            if (0 == result)
            {
                byte[] sendByte = new byte[21];
                sendByte[0] = (byte)(packNum / 256);
                sendByte[1] = (byte)(packNum % 256);
                sendByte[2] = result;
                Buffer.BlockCopy(uniformNum, 0, sendByte, 3, 16);
                Buffer.BlockCopy(carType, 0, sendByte, 19, 2);
                return sendByte;
            }
            else
            {
                byte[] sendByte = new byte[3];
                sendByte[0] = (byte)(packNum / 256);
                sendByte[1] = (byte)(packNum % 256);
                sendByte[2] = result;
                return sendByte;
            }
        }

        /// <summary>
        /// 请求教学人员登录信息应答
        /// </summary>
        /// <param name="uniformNum"></param>
        /// <param name="result"></param>
        /// <param name="carType"></param>
        /// <returns></returns>
        static public byte[] requestTeacherLoginInfoResponse(byte[] uniformNum, byte result, byte[] carType)
        {
            if (0 == result)
            {
                byte[] sendByte = new byte[19];
                Buffer.BlockCopy(uniformNum, 0, sendByte, 0, uniformNum.Length);
                sendByte[16] = result;
                Buffer.BlockCopy(carType, 0, sendByte, 17, 2);

                return sendByte;
            }
            else
            {
                byte[] sendByte = new byte[17];
                Buffer.BlockCopy(uniformNum, 0, sendByte, 0, uniformNum.Length);
                sendByte[16] = result;
                return sendByte;
            }
        }

        #endregion

    }
}
